public class Sorter {

    public int[] sort( int[] a ) {
        // 实现排序并返回一个新数组
        int[] b=new int [a.length];
        for(int i = 0 ; i < a.length - 1 ; i++){
            b[i]=a[i];
        }
        for (int i = 0 ; i < b.length - 1 ; i++) {
            for (int j = 0; j < b.length - 1 - i ; j++) {
                if( b[ j ] > b[ j + 1 ] ) {
                    b[ j ] ^= b[ j + 1 ] ;
                    b[ j + 1 ] ^= b[ j ] ;
                    b[ j ] ^= b[ j + 1 ] ;
                }
            }
            
        }
        return b;
    }

    public void traversal(int[] array) {
        if (array != null && array.length > 0) {
            for (int i = 0; i < array.length; i++) {
                System.out.print(array[i]);
                System.out.print((i < array.length - 1) ? " , " : "");
            }
            System.out.println();
        }
    }

    public static void main(String[] args) {
        Sorter sorter = new Sorter();

        int[] a = { 1, 100, -20, 99, 1000, 0, 30 };
        System.out.print("原数组: ");
        sorter.traversal(a); // 原数组: 1 , 100 , -20 , 99 , 1000 , 0 , 30

        int[] x = sorter.sort(a);
        System.out.print("新数组: ");
        sorter.traversal(x); // 新数组: -20 , 0 , 1 , 30 , 99 , 100 , 1000

        System.out.print("原数组: ");
        sorter.traversal(a); // 原数组: 1 , 100 , -20 , 99 , 1000 , 0 , 30
    }
}